﻿<!DOCTYPE html>
<html lang="zh-cmn-Hans">
    <head>
        <title>云印南天——找回密码</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link href="__CDNLIB__/bootstrap/3.3.2/css/bootstrap.min.css" rel="stylesheet" type="text/css" media="all"/>
    </head>
    <body>
        <div class="container">
            <div class="col-lg-8 col-lg-offset-2">
                <h1 class="text-danger text-center">找回密码</h1>
                <div class='alert alert-warning'>
                    为了防止你的账号信息滥用，你可以通过手机验证、邮箱验证，找回你的密码。
                    <br/>如果账号尚未注册请联系我们：contact@yunyin.org</br>返回：<a title="云印南天打印店" href="/Printer/Index/index">云印南天打印店首页</a>
                </div>
            </div>
		</div>	
		<div class="text-center">
			<button class="btn switch-btn" onclick="findWay(1)" id="phone_way">通过绑定手机找回</button>
			<button class="btn switch-btn" onclick="findWay(2)" id="email_way">通过绑定邮箱找回</button>
		</div>		
			
			<div class="col-lg-8 col-lg-offset-2">        
				<form style="display:none;" id='phone_form' role="form" method="post" onsubmit="return byPhone(this);" action="__URL__/findPwd">
                    <div class="text-center text-info">
						<h2>验证手机并重设密码</h2>
					</div>	
					<div class="input-group">
                        <label class="input-group-addon"  for="account">账号</label>
                        <input  class="form-control" placeholder='注册的账号' name="account" type="text" pattern="\w{3,16}$" id="account" required>
                    </div>
                    <div class="form-group input-group">
                        <label class="input-group-addon"  for="phone">手机</label>
                        <input  class="form-control" placeholder='绑定的手机号码' name="phone" type="text" pattern="1[3458]\d{9}" id="phone" required>
					</div> 
					  <input name="way" type="hidden" value="phone"/>
					<div class="text-center">
                        <button type="submit" class="btn btn-lg btn-success">提交</button>
                    </div>	                                 
                </form>
			</div>
			
			<div class="col-lg-8 col-lg-offset-2">              
				<form style="display:none;" id="email_form" role="form" method="post" action="__URL__/findPwd">
                    <div class="text-center text-info">
						<h2>验证邮箱并重设密码</h2>
					</div>
				   <div class="input-group">
                        <label class="input-group-addon"  for="account">账号</label>
                        <input  class="form-control" placeholder='注册的账号' name="account" type="text" pattern="\w{3,16}$" id="account" required>
                    </div>
                    <div class="form-group input-group">
                        <label class="input-group-addon"  for="email">邮箱</label>
                        <input  class="form-control" placeholder='绑定的邮箱地址' name="email" type="text" id="email" required>
                    </div>
						<input name="way" type="hidden" value="email"/>
                    <div class="text-center">
                        <button type="submit" class="btn btn-lg btn-success">提交</button>
                    </div>
                </form>
            </div>
        </div>
    </body>
	
	<div class="modal fade" id="Modal" tabindex="-1" role="dialog" aria-labelledby="ModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h3 class="modal-title" id="ModalLabel">稍等……</h3>
				</div>
				<div class="modal-body">正在提交</div>
			</div>
		</div>
	</div>
	<script src="__CDNLIB__/jquery/2.1.1/jquery.min.js"></script>
	<script src="__CDNLIB__/bootstrap/3.3.0/js/bootstrap.min.js" defer="defer"></script>
    <script>
	M=$('#Modal');
function checkform(f){
    if(f.password.value!=f.re_password.value)
    {
        f.password.focus=true;
        alert('两次密码不一致！');
        return false;
    }else{
        //此处应该md5(password)
        //f['isMD5'].value=1;
        return true;
    }
}

//验证手机
function byPhone() {
		f=document.getElementById('phone_form');
		var phone=f['phone'].value;
        var Mh = M.find('.modal-title');
        var Mb = M.find('.modal-body');
        Mh.html('稍等...');
        Mb.html('正在给' + phone + '发送验证码...');
        M.modal('show');
        var url = '/Printer/Printer/findPwd';
        var data = {
            'phone': phone,
			'account':f['account'].value,
			'way':'phone'
        }
        f.disabled=true;
        $.post(url, data, function(data, status) {
            if (status) {
                if (data.status) {
                        Mh.html('发送成功 验证手机');
                            Mb.html("<div class='input-group'><input id='code' name='code' type='text' class='form-control' placeholder='六位数字验证码' autocomplete='off' required/><span class='input-group-btn'><button class='btn btn-success' onclick='checkSMSCode(this);'>开始验证</button><button id='resend' class='btn' onclick='byPhone();' disabled>重发验证码</button></span></div><br>");
                        count(document.getElementById("resend"), 60);
                        M.modal('show');
                    }else{
                    Mh.html('发送失败');
                    Mb.html(data.info);
                }
            } else {
                Mh.html('异常');
                Mb.html('服务器通讯异常！');
            }
        M.modal('show');
      f.disabled=false;
        });
	return false;
}
//手机验证码
function checkSMSCode(b) {
    b.disabled = true;
    var c = $('#code');
    var code = c.val();
    reg = /^\d{6}$/;
    if (!reg.test(code)) {
        alert('验证码是四到六位数字哦!');
    } else {
        var url = '/Printer/Printer/checkSMSCode';
        var data = {
            'code': code,
        };
        $.post(url, data, function(d, status) {
            if (status) {
                if (d.status) {
                    M.find('.modal-title').html('验证成功');
                    M.find('.modal-body').html(d.info);
                    M.modal('show');
					location.href=d.url;
                    var pd = $('#phone_detail');
                    var bp = $('#bind_phone');
                    pd.children('.label').html(bp.children('input').val());
                    bp.hide().prev().show(100);
                } else if(d.url) {
                    M.find('.modal-title').html('验证失败');
                    M.find('.modal-body').html(d.info);
                }else{
                    alert('验证失败:' + d.info);
                }
            } else {
                alert('服务器通讯异常！');
            }
        });
    }
    b.disabled = false;
}
//重发倒计时
        function count(btn, c) {
                if (c > 0) {
                                btn.innerHTML = (c--) + 's可重发';
                        setTimeout(function() {
                        count(btn, c);
                }, 1000);
                } else {
                    btn.removeAttribute("disabled");
                        btn.innerHTML = "重发验证码";
        }
};
function findWay(w)
{
	$('.switch-btn').removeClass('btn-success');
	$('form').hide();
	switch (w)
	{
	case 1:
		$('#phone_way').addClass('btn-success')
		$('#phone_form').show();
		break;
	case 2:
		$('#email_way').addClass('btn-success')
		$('#email_form').show();
		break;
	}
}	
</script>
</html>